var G = {};

var data = {
	lang:'zh-CN',
	currency_id:'86',
	symbol:'￥',
	symbol_right:'CNY',
	label:'中文',
	standard:true,
	img:'https://static.shopsuite.cn/shopsuite/flags/square/5322affbc4d56.png',
	items:[
		{
			lang:'zh-CN',
			currency_id:'86',
			symbol:'￥',
			symbol_right:'CNY',
			label:'中文',
			standard:true,
			img:'https://static.shopsuite.cn/shopsuite/flags/square/5322affbc4d56.png'
		}
		
	]
}

try {
	if  (uni.getStorageSync('selang'))
	{

	}
	else
	{
		const res = uni.getSystemInfoSync();
		//如果不在允许的语言内，可重置
		uni.setStorageSync('selang', data.lang);
		uni.setStorageSync('standard', data.standard);
	}

	//默认显示方式
	uni.setStorageSync('standard', true);
		
	data.lang = uni.getStorageSync('selang')
	data.standard = uni.getStorageSync('standard')
} catch (e) {
	// error
}

try {
    if  (uni.getStorageSync('currency_id'))
    {
        data.currency_id = uni.getStorageSync('currency_id')
    }
    else
    {
        uni.setStorageSync('currency_id', data.currency_id);
    }
} catch (e) {
    // error
}


for(let idx in data.items)
{
	if(data.items[idx].lang == data.lang){
		data.label = data.items[idx].label
		data.img = data.items[idx].img


		data.currency_id = data.items[idx].currency_id
		data.symbol = data.items[idx].symbol
		data.symbol_right = data.items[idx].symbol_right
		data.standard = data.items[idx].standard

		break;
	}
}


function __(str)
{	
	// return str;

	//let lang = uni.getStorageSync('selang');
	//lang = 'en-US';
	if (typeof G[data.lang] == 'undefined' || typeof G[data.lang][str] == 'undefined' || G[data.lang][str]==null)
	{
		return str
	}
	else
	{
		if(data.currency_id == '86')
		{
			return str;
		}
		else
		{
			return G[data.lang][str].replace(/￥/g, data.symbol).replace(/RMB|元/g, data.symbol_right);
		}
	}
}

function setLang(lang, standard, currency_id, symbol)
{	
	data.lang = lang
	data.standard = standard
	data.currency_id = currency_id
	
	//symbol
	data.symbol = symbol
}

export default {
	__:__,
	setLang:setLang,
	lang:data.lang,
	standard:data.standard,
	currency_id:data.currency_id,
	symbol:data.symbol,
	label:data.label,
	img:data.img,
	data:data,
	G:G
}
